<template>
  <work-template @submitOn="submitOn" v-model="ruleForm"
                 @closeSelectedTag="closeSelectedTag" :butShow="bool">
    <div slot="form" class="container-div">
      <new-application v-model="ruleForm" :state="isEdit" ref="refNewApplication"/>
    </div>

  </work-template>
</template>

<script>
import * as apis from '@/api/vehicleDisposal/routineApplyFor.js'

export default {
  name: 'RoutineApplyForNew',
  components: {
    newApplication: () => import('../../components/routineDisposal/routineApplyFor/newApplication.vue')
  },
  computed: {
    isEdit() {
      if (this.$route.query.type === "edit") {
        return "write";
      }
      if (this.$route.query.type === "view") {
        return "readonly";
      }
    },
    bool() {
      if (this.$route.query.type === "edit") {
        return true;
      }
      if (this.$route.query.type === "view") {
        return false;
      }
    },
  },
  watch: {},
  data() {
    return {
      ruleForm: {
        carId: null,
        carNo: '',
        vinNo: '',
        brandId: '',
        seriesId: '',
        modelId: '',
        brandName: '',
        modelName: '',
        seriesName: '',
        propertyRightId: '',
        propertyRightName: '',
        registerTime: '',
        carAge: '',
        environmentalStandards: '',
        licenseNature: '',
        fuelType: '',
        liter: '',
        seatNum: '',
        gearPosition: '',
        exteriorColor: '',
        carType: '',
        accidentAmountThreeYears: '',
        guidancePrice: '',
        purchasePrice: '',
        initialResidualValue: '',
        mileage: '',
        transferCount: '',
        vehicleConditionLevel: '',
        cityName: '',
        disposalReason: '',
        vehicleStatus: '',
        attachment: ''
      }
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    submitOn() {
      this.$refs.refNewApplication.handleEffect().then(() => {
        const loading = this.$loading({
          lock: true,
          text: '保存中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        apis.vehicleDisposal(this.ruleForm).then(res => {
          if (res.code === 200) {
            this.$message.success('保存成功')
            loading.close()
            this.closeSelectedTag()
          }
        }).catch(() => {
          loading.close()
        })
      }).catch(err => {

      })
    },

    closeSelectedTag() {
      let path = ''
      if (this.$route.query.path === 'RoutineForewarningList') {
        path = '/VehicleDisposal/RoutineDisposal/RoutineForewarningList'
      }
      if (this.$route.query.path === 'RoutineApplyForList') {
        path = '/VehicleDisposal/RoutineDisposal/RoutineApplyForList'
      }
      this.$tab.closePage().then(({visitedViews}) => {
        this.$router.push({
          path: path,
        });
      });
    }
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/container.scss";
</style>


